﻿$(function(){
    var queryString = nehnre.queryString();
    $(".STYLE17").html(queryString["departName"]);
    $("#departId").val(queryString["departId"]);
    $("input[name*='textfield']").each(function(){
        var mark = $(this).parent().prev().prev().prev().prev().text();
        $(this).attr("class","validate[custom[integer],max[{0}],min[0]] input-box".format(mark));
    });
    $("#formID").validationEngine();
    $.ajax({
        url:"ashx/load_mark.ashx",
        data: "departId={0}".format(queryString["departId"]),
        cache: false,
        success:function(mark){
            console.log(mark.split(",").length);
            var arrmark = mark.split(",");
            var current = 0;
            for(var i = 0;i < arrmark.length; i++){
                if(arrmark[i]){
                    $("#textfield{0}".format(i + 1)).val(arrmark[i]);
                    current ++;
                }
            }
            
            var total = $("input[name*=textfield]").size();
		    $("#proccess").text(current);		    $("#proccess").progressBar({ 
		        max: total, 
		        textFormat: 'fraction',
		        showText: false,
		        width:150,
		        boxImage:'../style/images/zcb_15_150.gif',
		        barImage:{0:'../style/images/zcb_16_150.gif'}
		     }); 
		    $("#total").html(total);
		    $("#current").html(current); 
		    
        }
    });
    
    $("#save").click(function(){
        var isValidatable = $('#formID').validationEngine('validate');
        if(isValidatable){
            $.ajax({
                url:"ashx/SaveDetail.ashx",
                data: $("#formID").serialize(),
                success:function(b){
                    b = nehnre.parseJSON(b);
                    if(b){
                        alert("保存成功！");
                        var total = $(":text").size();
                        var current = 0;
                        $(":text").each(function(){
                            if($(this).val()){
                                current ++;
                            }
                        });
                        $("#proccess").html("");
	                    $("#proccess").text(current);		                $("#proccess").progressBar({ 
		                    max: total, 
		                    textFormat: 'fraction',
		                    showText: false,
		                    width:150,
		                    boxImage:'../style/images/zcb_15_150.gif',
		                    barImage:{0:'../style/images/zcb_16_150.gif'}
		                 });
		                $("#total").html(total);
		                $("#current").html(current); 		                                          
                    } else {
                        alert("保存失败");
                    }
                }
            });
        }
    });    
});